package com.aispeech.task.lasr.event;

import com.aispeech.task.common.data.domain.Task;
import com.aispeech.task.fsm.Event;
import com.aispeech.task.fsm.EventType;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ErrorEvent extends Event<Task> {
    public ErrorEvent(Task task) {
        super(EventType.Error, task);
    }

    @Override
    public Event fire() {
        Task task = this.getTarget();

        Event nextEvent;

        try {
            Thread.sleep(3000L);
            nextEvent = new SplitChannelEvent(task);

        } catch (InterruptedException ex) {
            nextEvent = new ErrorEvent(task);
        }

        log.info("[ ErrorEvent.fire ]: {} fired. next: {}", this, nextEvent.eventType());

        return nextEvent;
    }
}
